<?php
namespace Home\Controller;
class ShopsController extends HomeController {
	public function index(){
          if(!is_login()){
                 $this->error('请登录查看',U('User/login'));   
                }
        $username=get_username();
        $shop=M('gou')->where(array('uername'=>$username))->select();
        foreach ($shop as $v) {
            $id=$v['gid'];
            $shu=$v['shu'];
            $price=M('price')->where(array('ar'=>$shu))->find();
            $pic=M('shop')->where(array('id'=>$id))->find();
            $zongjia+=$price['sprice']*$v['num'];
            $prices[]=$price['sprice'];
            $picd[]=$pic['pic'];
            $title[]=$pic['title'];
        }
        $this->assign('zongjia',$zongjia);
        $this->assign('prices',$prices);
        $this->assign('title',$title);
        $this->assign('picd',$picd);
        $this->assign('shop',$shop);
		$this->display();
	}
	  public function add(){
    	$_POST['gid']=I('post.gid');
    	$_POST['num']=I('post.num');
    	$_POST['uername']=I('post.name');
        $_POST['shu']=I('post.ss');
        $_POST['addtime']=time();
        $_POST['ding']=time().rand();
        $car=M('gou');
        if (!empty($_POST['uername'])) {
             $res=$car->add( $_POST);
        if($res){
            $data['status']=1;
            $data['info']='添加成功';
        }else{
            $data['status']=0;
            $data['info']='添加失败';}
        }else{
             $data['info']='添加失败,请先登录登录';
        }
    	$this->ajaxReturn($data);
    }
    public function delete(){
        $id=I('GET.id');
        $res=M('gou')->where(array('id'=>$id))->delete();
        if ($res) {
           $this->success('删除成功',U('Shops/index'));
        }else{
            $this->error('删除失败',U('Shops/index'));
        }
     
    }
}